package com.bawei.week.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bawei.lib_base.entity.NoticeBeanItem
import com.bawei.week.R
import com.bawei.week.databinding.ItemNoticeBinding

class NoticeAdapter : PagingDataAdapter<NoticeBeanItem,NoticeAdapter.NoticeViewHolder>(diffUtil){
    companion object{
        val diffUtil = object : DiffUtil.ItemCallback<NoticeBeanItem>(){
            override fun areItemsTheSame(oldItem: NoticeBeanItem,newItem: NoticeBeanItem): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(oldItem: NoticeBeanItem, newItem: NoticeBeanItem): Boolean {
                return oldItem.id == newItem.id
            }
        }
    }

    override fun onBindViewHolder(holder: NoticeAdapter.NoticeViewHolder, position: Int) {
        holder.binding?.bean = getItem(position)
    }

    class NoticeViewHolder(itemView : View) : ViewHolder(itemView){
        val binding : ItemNoticeBinding?= DataBindingUtil.bind<ItemNoticeBinding>(itemView)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoticeAdapter.NoticeViewHolder {
        val inflate = LayoutInflater.from(parent.context).inflate(R.layout.item_notice,parent,false)
        return NoticeViewHolder(inflate)
    }
}